home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group03a.txt
/
000044_icon-group-sender_Tue Mar 25 16:50:34 2003.msg
< prev
next >
Wrap
Internet Message Format
|
2003-12-22
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h2PNnPs18801
for icon-group-addresses; Tue, 25 Mar 2003 16:49:25 -0700 (MST)
Message-Id: <200303252349.h2PNnPs18801@baskerville.CS.Arizona.EDU>
X-Authentication-Warning: weaver.tuc.noao.edu: swampler set sender to swampler@noao.edu using -f
Subject: Re: newbie question -- ressurected
From: Steve Wampler <swampler@noao.edu>
To: Quiet Voice <voice_of_reason@australia.edu>
Cc: icon-group@cs.arizona.edu
Date: 25 Mar 2003 13:37:47 -0700
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
On Tue, 2003-03-25 at 11:44, Quiet Voice wrote:
> Greetings:
>
> Several years ago, I made a brief foray into trying to teach myself
> the ICON programming language and develop some text analysis software.
> After several fits-n-starts, the project sort of died on the vine.
>
> I'm back at it again. Now, I'm trying to dig thru past code, remind
> myself of what it was supposed to do and how...and shake out the
> kinks.
>
> I ran a piece of code this morning and discovered that it results in
> an infinite loop.....but I can't figure out why.
>
> here is the code fragment:
>
> while not((line := read(data)) == "") do every
> write(lettercount[!line] +:= 1)
>
> {Note, this is one continuous line in the actual code}
> "data" is an input text file
>
> >From some debugging I've done, it seems like it keep reading from the
> file after it reaches the end...it just loops back to the begining of
> the file and starts over again. But I don't figure out why.
>
> What am I missing?
I don't think it's looping back. What is happening is
that when the read(data) fails, the 'not' is converting that failure
back into success (that's your infinite loop).
Since the assignment to line is performed after the read but before
invoking not, line is retaining its last value (i.e. last line of the
file), so you're seeing the characters in that last line counted over
and over again.
'not' is a tricky beast and shouldn't be confused with the not
boolean operators in other languages. In particular, you have
two different points of failure in you while test clause and want
to do different things on each. While 'not' might be appropriate
for one of those (the X == "") part, it isn't appropriate for
the other.
Why not just try:
while line := read(data) do
every lettercount[!line] +:= 1
instead of the above loop? (Yes, it doesn't print out each count as
you compute it, but that's probably left over from debugging
anyway.) Empty lines will produce no characters in the ! operation,
so you don't have to test for them.
(You can shorten the above even more, but that's probably
not particularly important...)
Hope that helps!
--
Steve Wampler <swampler@noao.edu>
National Solar Observatory